home *** CD-ROM | disk | FTP | other *** search
- /*****************************************************************************/
- /* (C) 1993,1994 R. NADE - M. GRANDCHAMP - All Rights Reserved */
- /*****************************************************************************/
- /* This source-code is NOT public domain nor Freeware, this is part of */
- /* 'The C Programming Package' which is Shareware. */
- /* If you use this code, please register and get a free Full-VGA version */
- /*****************************************************************************/
- /*-------------------*
- * CPPLGEN1.C *
- * Mouse programs *
- * & utilities *
- *-------------------*/
-
- /* Included Files */
- # include <stdio.h>
- # include <io.h>
- # include <dos.h>
- # include <fcntl.h>
- # include <bios.h>
- # include <stdlib.h>
- # include <conio.h>
- # include <alloc.h>
- # include <process.h>
- # include <time.h>
- # include <alloc.h>
- # include <string.h>
-
- /* Global Variables */
- extern int bm,i,j,k,l,m,n,t,x,xm,y,ym,z,soundvar,button,x1,x2,y1,y2,xms,yms;
- extern int divx,divy,xmsa,ymsa;
- extern unsigned int jouract,monthact,yearact;
- extern unsigned char nc1[],nc2[],trashret[];
- extern unsigned char screen[],screen2[],screenhelp[];
- extern struct text_info ti;
- extern struct text_info thelp;
-
- /*---------*
- * SOUND 1 *
- *---------*/
- void sound1()
- {
- if(soundvar==1){
- sound(500); delay(200);
- nosound();
- }
- }
- /*---------*
- * SOUND 2 *
- *---------*/
- void sound2()
- {
- if(soundvar==1){
- sound(300); delay(100);
- sound(500); delay(200);
- sound(700); delay(100);
- nosound();
- }
- }
- /*---------------*
- * SOUND 3 *
- * right answer *
- *---------------*/
- void sound3()
- {
- if(soundvar==1){
- sound(300); delay(100);
- sound(500); delay(200);
- sound(300); delay(100);
- sound(700); delay(100);
- sound(1000); delay(300);
- nosound();
- }
- }
- /*---------------*
- * SOUND 4 *
- * wrong answer *
- *---------------*/
- void sound4()
- {
- if(soundvar==1){
- sound(300); delay(100);
- sound(500); delay(100);
- sound(300); delay(200);
- sound(200); delay(200);
- sound(150); delay(200);
- nosound();
- }
- }
- /*-----------------*
- * CHECK THE MOUSE *
- *-----------------*/
- int check_the_mouse()
- {
- union REGS inregs,outregs;
- inregs.x.ax=0x00;
- int86(0x33,&inregs,&outregs);
- k=outregs.x.ax;
- if(k==0) return(0);
- else return(1);
- }
- /*---------------*
- * PUT THE MOUSE *
- *---------------*/
- void put_the_mouse(enx,eny)
- int enx,eny;
- {
- union REGS inregs,outregs;
- /* co-ordinates are in pixels, we convert them in lines */
- /* and columns using the factors depending upon the */
- /* videocard */
- inregs.x.ax=0x04; inregs.x.cx=(enx-1)*divx;
- inregs.x.dx=(eny-1)*divy; int86(0x33,&inregs,&outregs);
- }
- /*-----------------*
- * LIMIT THE MOUSE *
- *-----------------*/
- void limit_the_mouse()
- {
- union REGS inregs,outregs;
- /* co-ordinates are in pixels, we convert them in lines */
- /* and columns using the factors depending upon the */
- /* videocard */
- /* Horizontal limits between 0 and 80 columns */
- inregs.x.ax=0x07; inregs.x.cx=((x1-1)*divx);
- inregs.x.dx=((x2-1)*divx); int86(0x33,&inregs,&outregs);
- /* Vertical limits between 0 and 25, 43, 50 lines */
- inregs.x.ax=0x08; inregs.x.cx=((y1-1)*divy);
- inregs.x.dx=((y2-1)*divy); int86(0x33,&inregs,&outregs);
- /* The put the mouse in the upper-left corner */
- /* of this new window */
- put_the_mouse((x1+1),(y1+1));
- }
- /*----------------*
- * SHOW THE MOUSE *
- *----------------*/
- void show_the_mouse()
- {
- union REGS inregs,outregs;
- inregs.x.ax=0x01; int86(0x33,&inregs,&outregs);
- }
- /*----------------*
- * HIDE THE MOUSE *
- *----------------*/
- void hide_the_mouse()
- {
- union REGS inregs,outregs;
- inregs.x.ax=0x02; int86(0x33,&inregs,&outregs);
- }
- /*-----------------*
- * GET MOUSE STATE *
- *-----------------*/
- void get_mouse_state()
- {
- union REGS inregs,outregs;
- inregs.x.ax=0x03; int86(0x33,&inregs,&outregs);
- button=outregs.x.bx;
- x=outregs.x.cx; y=outregs.x.dx;
- xm=(x/divx)+1; ym=(y/divy)+1;
- if(button>0){
- /* at least, one button has been pressed */
- bm=1; delay(200);
- }
- else bm=0;
- }
- /*-----------------*
- * GET SYSTEM DATE *
- *-----------------*/
- void get_the_system_date()
- {
- struct date d;
- /* Results are integers */
- getdate(&d); yearact=d.da_year;
- monthact=d.da_mon; jouract=d.da_day;
- }
- /*-----------------------*
- * LEFT JUSTIFY THE TEXT *
- *-----------------------*/
- void left_justify_the_text(thetext,nbcars)
- unsigned char thetext[81];
- int nbcars;
- {
- i=strlen(thetext);
- /* Fill the beginning of trashret[] with the chars */
- for(j=0; j<i; j++) trashret[j]=thetext[j];
- /* And the rest with spaces */
- for(j=i; j<nbcars; j++) trashret[j]=0x20;
- trashret[nbcars]=0x00;
- }
- /*------------------------*
- * RIGHT JUSTIFY THE TEXT *
- *------------------------*/
- void right_justify_the_text(thetext,nbcars)
- unsigned char thetext[81];
- int nbcars;
- {
- i=strlen(thetext); k=nbcars-i;
- /* Fill the beginning of trashret[] with spaces */
- for(j=0; j<k; j++) trashret[j]=0x20;
- /* And the rest with the chars */
- for(j=0; j<i; j++) trashret[k+j]=thetext[j];
- trashret[nbcars]=0x00;
- }
- /*-----------------------------------------*
- * RIGHT JUSTIFY (numeric variable,nbcars) *
- * with less than 5 chars in nc2[] *
- *-----------------------------------------*/
- void right_justify(variable,nbcars)
- int variable,nbcars;
- {
- itoa(variable,nc1,10);
- if(variable<10){
- nc1[3]=nc1[0]; nc1[0]=0x20;
- nc1[1]=0x20; nc1[2]=0x20;
- nc1[4]=0x00;
- }
- if((variable>9)&&(variable<100)){
- nc1[3]=nc1[1]; nc1[2]=nc1[0];
- nc1[0]=0x20; nc1[1]=0x20;
- nc1[4]=0x00;
- }
- if((variable>99)&&(variable<1000)){
- nc1[3]=nc1[2]; nc1[2]=nc1[1];
- nc1[1]=nc1[0]; nc1[0]=0x20;
- nc1[4]=0x00;
- }
- if(variable==0){
- nc1[0]=0x20; nc1[1]=0x20;
- nc1[2]=0x20; nc1[3]=0x30;
- nc1[4]=0x00;
- }
- /* If the number if greater than 999, it is OK with 4 digits */
- /* Put it at the right size if less than 4 digits */
- if(nbcars==1){
- nc2[0]=nc1[3]; nc2[1]=0x00;
- }
- if(nbcars==2){
- nc2[0]=nc1[2]; nc2[1]=nc1[3];
- nc2[2]=0x00;
- }
- if(nbcars==3){
- nc2[0]=nc1[1]; nc2[1]=nc1[2];
- nc2[2]=nc1[3]; nc2[3]=0x00;
- }
- if(nbcars==4) strcpy(nc2,nc1);
- }
- /*-------------*
- * SAVE SCREEN *
- *-------------*/
- void save_screen()
- {
- /* Save the whole screen */
- hide_the_mouse(); gettext(1,1,80,25,screen);
- /* Save the current window info., the cursor position */
- /* and the mouse position */
- gettextinfo(&ti); show_the_mouse();
- xms=xm; yms=ym;
- }
- /*----------------*
- * RESTORE SCREEN *
- *----------------*/
- void restore_screen()
- {
- hide_the_mouse();
- /* Restore the saved screen */
- nc1[1]=0x00; puttext(1,1,80,25,screen);
- /* Use the values saved for the window, the cursor and */
- /* the mouse as before the save */
- nc1[0]=ti.winleft; x1=atoi(nc1);
- nc1[0]=ti.winright; x2=atoi(nc1);
- nc1[0]=ti.wintop; y1=atoi(nc1);
- nc1[0]=ti.winbottom; y2=atoi(nc1);
- xm=xms; ym=yms;
- /* Put the window to its initial value */
- window(x1,y1,x2,y2);
- /* Put the cursor at the same place */
- nc1[0]=ti.curx; x=atoi(nc1);
- nc1[0]=ti.cury; y=atoi(nc1);
- gotoxy(x,y);
- /* And the colours attributes */
- nc1[0]=ti.attribute; z=atoi(nc1);
- textattr(z); show_the_mouse();
- }
- /*------------------*
- * SAVE HELP SCREEN *
- *------------------*/
- void save_help_screen()
- {
- /* Save the full displayed screen */
- hide_the_mouse(); gettext(40,1,80,25,screenhelp);
- /* Save the current info. on the window */
- /* The position of the cursor and the mouse */
- gettextinfo(&thelp); show_the_mouse();
- xmsa=xm; ymsa=ym;
- }
- /*---------------------*
- * RESTORE HELP SCREEN *
- *---------------------*/
- void restore_help_screen()
- {
- /* display the saved window */
- nc1[1]=0x00; puttext(40,1,80,25,screenhelp);
- /* Use the values saved for the window, the cursor and */
- /* the mouse as before the save */
- nc1[0]=thelp.winleft; x1=atoi(nc1);
- nc1[0]=thelp.winright; x2=atoi(nc1);
- nc1[0]=thelp.wintop; y1=atoi(nc1);
- nc1[0]=thelp.winbottom; y2=atoi(nc1);
- xm=xmsa; ym=ymsa;
- /* Put the window to its initial value */
- window(x1,y1,x2,y2);
- /* Put the cursor at the same place */
- nc1[0]=thelp.curx; x=atoi(nc1);
- nc1[0]=thelp.cury; y=atoi(nc1);
- gotoxy(x,y);
- /* And the colours attributes */
- nc1[0]=thelp.attribute; z=atoi(nc1);
- textattr(z);
- }
- /*--------------------*
- * SAVE SCREEN 2 *
- *--------------------*/
- void save_screen2(enx,eny)
- int enx,eny;
- {
- /* Save the zone defined by the upper-left corner co-ordinates */
- /* given as parameters with 25 chars wide and 11 lines high */
- hide_the_mouse();
- gettext(enx,eny,(enx+25),(eny+11),screen2);
- show_the_mouse();
- }
- /*------------------*
- * RESTORE SCREEN 2 *
- *------------------*/
- void restore_screen2(enx,eny)
- int enx,eny;
- {
- /* Display the saved screen */
- hide_the_mouse();
- puttext(enx,eny,(enx+25),(eny+11),screen2);
- show_the_mouse();
- }
- /* End of the Module *//*--------------------*/
-
-